<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>MongoDB Dump | Introduction</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/part2/10.Python操作MongoDB.html" />
    
    
    <link rel="prev" href="../../home/part2/8.MongoDBIndex.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="3.9"
        data-chapter-title="MongoDB Dump"
        data-filepath="home/part2/9.MongoDBDump.md"
        data-basepath="../.."
        data-revision="Sun Oct 21 2018 20:49:12 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="home/NoSQL简介.html">
            
                
                    <a href="../../home/NoSQL简介.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        NoSQL介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="home/part1/Redis.html">
            
                
                    <a href="../../home/part1/Redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Redis
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/part1/1.常用命令.html">
            
                
                    <a href="../../home/part1/1.常用命令.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        常用命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/part1/2.Redis的数据类型.html">
            
                
                    <a href="../../home/part1/2.Redis的数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        Redis的数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="home/part1/3.Redis高级.html">
            
                
                    <a href="../../home/part1/3.Redis高级.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Redis高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="home/part1/4.python操作redis.html">
            
                
                    <a href="../../home/part1/4.python操作redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        python操作redis
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="home/part2/MongoDB.html">
            
                
                    <a href="../../home/part2/MongoDB.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        MongoDB
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/part2/1.MongoDB基础操作.html">
            
                
                    <a href="../../home/part2/1.MongoDB基础操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        MongoDB基础操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/part2/2.MongoDBDBS.html">
            
                
                    <a href="../../home/part2/2.MongoDBDBS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        MongoDB DBS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/part2/3.MongoDBCreate.html">
            
                
                    <a href="../../home/part2/3.MongoDBCreate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        MongoDB Create
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/part2/4.MongoDBUpdate.html">
            
                
                    <a href="../../home/part2/4.MongoDBUpdate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        MongoDB Update
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="home/part2/5.MongoDBDelete.html">
            
                
                    <a href="../../home/part2/5.MongoDBDelete.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        MongoDB Delete
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="home/part2/6.MongoDBRetrieve.html">
            
                
                    <a href="../../home/part2/6.MongoDBRetrieve.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        MongoDB Retrieve
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="home/part2/7.MongoDB查询条件.html">
            
                
                    <a href="../../home/part2/7.MongoDB查询条件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        MongoDB 查询条件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="home/part2/8.MongoDBIndex.html">
            
                
                    <a href="../../home/part2/8.MongoDBIndex.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        MongoDB Index
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.9" data-path="home/part2/9.MongoDBDump.html">
            
                
                    <a href="../../home/part2/9.MongoDBDump.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        MongoDB Dump
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="home/part2/10.Python操作MongoDB.html">
            
                
                    <a href="../../home/part2/10.Python操作MongoDB.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        Python操作MongoDB
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Introduction</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="mongodb-&#x5907;&#x4EFD;mongodump&#x4E0E;&#x6062;&#x590D;mongorestore">MongoDB &#x5907;&#x4EFD;(mongodump)&#x4E0E;&#x6062;&#x590D;(mongorestore)</h1>
<hr>
<h2 id="mongodb&#x6570;&#x636E;&#x5907;&#x4EFD;">MongoDB&#x6570;&#x636E;&#x5907;&#x4EFD;</h2>
<p>&#x5728;Mongodb&#x4E2D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;mongodump&#x547D;&#x4EE4;&#x6765;&#x5907;&#x4EFD;MongoDB&#x6570;&#x636E;&#x3002;&#x8BE5;&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x5BFC;&#x51FA;&#x6240;&#x6709;&#x6570;&#x636E;&#x5230;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E2D;&#x3002;</p>
<p>mongodump&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x5BFC;&#x51FA;&#x7684;&#x6570;&#x636E;&#x91CF;&#x7EA7;&#x8F6C;&#x5B58;&#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<h3 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h3>
<p>mongodump&#x547D;&#x4EE4;&#x811A;&#x672C;&#x8BED;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">&gt;mongodump -h dbhost -d dbname -o dbdirectory
</code></pre>
<ul>
<li><p><strong>-h&#xFF1A;</strong> B&#x6240;&#x5728;&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;127.0.0.1&#xFF0C;&#x5F53;&#x7136;&#x4E5F;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x7AEF;&#x53E3;&#x53F7;&#xFF1A;127.0.0.1:27017</p>
</li>
<li><p><strong>-d&#xFF1A;</strong> &#x9700;&#x8981;&#x5907;&#x4EFD;&#x7684;&#x6570;&#x636E;&#x5E93;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;test</p>
</li>
<li><p><strong>-o&#xFF1A;</strong> &#x5907;&#x4EFD;&#x7684;&#x6570;&#x636E;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;c:\data\dump&#xFF0C;&#x5F53;&#x7136;&#x8BE5;&#x76EE;&#x5F55;&#x9700;&#x8981;&#x63D0;&#x524D;&#x5EFA;&#x7ACB;&#xFF0C;&#x5728;&#x5907;&#x4EFD;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x7CFB;&#x7EDF;&#x81EA;&#x52A8;&#x5728;dump&#x76EE;&#x5F55;&#x4E0B;&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;test&#x76EE;&#x5F55;&#xFF0C;&#x8FD9;&#x4E2A;&#x76EE;&#x5F55;&#x91CC;&#x9762;&#x5B58;&#x653E;&#x8BE5;&#x6570;&#x636E;&#x5E93;&#x5B9E;&#x4F8B;&#x7684;&#x5907;&#x4EFD;&#x6570;&#x636E;&#x3002;</p>
</li>
</ul>
<h3 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h3>
<p>&#x5148;&#x9000;&#x51FA;mongo&#x5BA2;&#x6237;&#x7AEF;</p>
<pre><code class="lang-sql">mongodump -d py4 -o /home/yc/data/
</code></pre>
<h2 id="mongodb&#x6570;&#x636E;&#x6062;&#x590D;">MongoDB&#x6570;&#x636E;&#x6062;&#x590D;</h2>
<p>mongorestore&#x547D;&#x4EE4;&#x811A;&#x672C;&#x8BED;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">&gt;mongorestore -h &lt;hostname&gt;&lt;:port&gt; -d dbname &lt;path&gt;
&#x9000;&#x51FA;mongo&#x5BA2;&#x6237;&#x7AEF;&#x6267;&#x884C;
mongorestore -d py /home/yc/data/py4
</code></pre>
<pre><code class="lang-sql">--host &lt;:port&gt;, -h &lt;:port&gt;&#xFF1A; MongoDB&#x6240;&#x5728;&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#xFF1A; localhost:27017

--db , -d &#xFF1A;&#x9700;&#x8981;&#x6062;&#x590D;&#x7684;&#x6570;&#x636E;&#x5E93;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;test&#xFF0C;&#x5F53;&#x7136;&#x8FD9;&#x4E2A;&#x540D;&#x79F0;&#x4E5F;&#x53EF;&#x4EE5;&#x548C;&#x5907;&#x4EFD;&#x65F6;&#x5019;&#x7684;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x6BD4;&#x5982;test2

--drop&#xFF1A;&#x6062;&#x590D;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5148;&#x5220;&#x9664;&#x5F53;&#x524D;&#x6570;&#x636E;&#xFF0C;&#x7136;&#x540E;&#x6062;&#x590D;&#x5907;&#x4EFD;&#x7684;&#x6570;&#x636E;&#x3002;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x6062;&#x590D;&#x540E;&#xFF0C;&#x5907;&#x4EFD;&#x540E;&#x6DFB;&#x52A0;&#x4FEE;&#x6539;&#x7684;&#x6570;&#x636E;&#x90FD;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x614E;&#x7528;&#x54E6;&#xFF01;

&lt;path&gt;&#xFF1A;mongorestore &#x6700;&#x540E;&#x7684;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BBE;&#x7F6E;&#x5907;&#x4EFD;&#x6570;&#x636E;&#x6240;&#x5728;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;c:\data\dump\test&#x3002;

&#x4F60;&#x4E0D;&#x80FD;&#x540C;&#x65F6;&#x6307;&#x5B9A; &lt;path&gt; &#x548C; --dir &#x9009;&#x9879;&#xFF0C;--dir&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5907;&#x4EFD;&#x76EE;&#x5F55;&#x3002;

--dir&#xFF1A;&#x6307;&#x5B9A;&#x5907;&#x4EFD;&#x7684;&#x76EE;&#x5F55; &#x4F60;&#x4E0D;&#x80FD;&#x540C;&#x65F6;&#x6307;&#x5B9A; &lt;path&gt; &#x548C; --dir &#x9009;&#x9879;&#x3002;

&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;:
</code></pre>
<pre><code class="lang-sql">&gt;mongorestore
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/part2/8.MongoDBIndex.html" class="navigation navigation-prev " aria-label="Previous page: MongoDB Index"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/part2/10.Python操作MongoDB.html" class="navigation navigation-next " aria-label="Next page: Python操作MongoDB"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
